<!--
 * @Description:车辆维修信息主界面
 * @Autor: 刘诗文
 * @Date: 2020-12-10 17:20:15
 * @LastEditors: 刘诗文
 * @LastEditTime: 2021-02-02 19:46:52
-->
<template>
  <div>
    <FilterTable
      ref="table"
      height="500"
      selectionType="single"
      :columns="columns"
      :fetchapi="localOrderHistoryFetchapi"
      :isSelectColumn="false"
      :params="localOrderHistoryFetchParams"
      :datakey="'rows'"
      columnsRef="vehicleMaintenancelsw"
      :onColumnsChange="columns => (this.columns = columns)"
      :onRowSelectChange="onRowSelectChange"
    >
    </FilterTable>
    <!-- 本地维修历史详情 -->
    <BaseDialog :visible.sync="showLocalOrderHistoryDetailPanel" title="工单详情" destroyOnClose :containerStyle="{ height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px' }">
      <orderDetail :repairTypeDict="repairTypeDict" :sfqfDict="sfqfDict" :orderInfo="selectedLocalHistoryOrder" @close="showLocalOrderHistoryDetailPanel = false" />
    </BaseDialog>
  </div>
</template>
<script>
import { dictionary } from '@/utils/dictMixin';
import { confirmAction, notifyAction, findFormItem, findTableItem } from '@/utils';
import { getAllUser } from '@/api/customerRepair/afterSaleVisit/resultEntry';

import { getWxlxSelect, getSfqfSelect, queryLocalRepairHistory } from '@/api/repair/repairReception/customer';

import orderDetail from '@/pages/repair/repairReception/customer/repairHistory/orderDetail';

export default {
  name: 'vehicleMaintenance',
  components: {
    orderDetail
  },
  mixins: [dictionary],
  props: ['resData'],

  data() {
    this.selectedData = null;
    this.BaseTable = null;
    this.repairTypeDict = []; // 维修类型字典
    this.sfqfDict = []; // 收费区分字典
    this.selectedLocalHistoryOrder = {}; // 选中查看的本地工单
    return {
      columns: this.createTableColumns(),
      localOrderHistoryFetchapi: queryLocalRepairHistory,
      localOrderHistoryFetchParams: { vin: this.resData.vin },

      showLocalOrderHistoryDetailPanel: false // 是否显示本地维修历史详情弹窗
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table;
    this.initDictCode();
  },
  methods: {
    createTableColumns() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'operation',
          width: 80,
          render: props => {
            return (
                <div style="text-align:center">
                  <el-button type="text" onClick={() => {this.openHandler(props.row);}}>
                    明细
                  </el-button>
                </div>
            );
          }
        },
        {
          title: '工单号',
          dataIndex: 'RO_NO'
        },
        {
          title: '车牌号',
          dataIndex: 'LICENSE'
        },
        {
          title: '维修类型',
          dataIndex: 'REPAIR_TYPE_CODE',
          dictItems: []
        },
        {
          title: '进厂里程',
          dataIndex: 'IN_MILEAGE'
        },
        {
          title: '开单日期',
          dataIndex: 'RO_CREATE_DATE',
          dateFormat: 'yyyy-MM-dd'
        },
        {
          title: '服务顾问',
          dataIndex: 'SERVICE_ADVISOR',
          dictItems: []
        },
        {
          title: '工单状态',
          dataIndex: 'RO_STATUS',
          dictItems: this.createDictList(8049)
        }
      ];
    },
    onRowSelectChange(row) {
      if (!row.length) {
        this.selectedData = null;
      } else {
        this.selectedData = row[0];
      }
    },
    openHandler(val) {
      this.selectedLocalHistoryOrder = val;
      this.showLocalOrderHistoryDetailPanel = true;
    },
    // 获取字典值
    initDictCode() {
      this.queryRepairTypeDict();
      this.querySfqfDict();
      // 获取所有人员信息
      this.getAllUser();
    },
    // 获取维修类型
    async queryRepairTypeDict() {
      let res = await getWxlxSelect();
      if (res.resultCode == 200) {
        this.repairTypeList = res.data;
        let repairTypeDict = res.data.map(item => ({ text: item.REPAIR_TYPE_NAME, value: item.REPAIR_TYPE_CODE + '' }));
        this.repairTypeDict = repairTypeDict;
        let targetTableItems = [findTableItem(this.columns, 'REPAIR_TYPE_CODE')];
        targetTableItems.forEach(item => {
          item.dictItems = item.filterItems = repairTypeDict;
        });
      }
    },
    // 获取收费区分
    async querySfqfDict() {
      let res = await getSfqfSelect();
      if (res.resultCode == 200) {
        let sfqfDict = res.data.map(item => ({ text: item.CHARGE_PARTITION_NAME, value: item.CHARGE_PARTITION_CODE }));
        this.sfqfDict = sfqfDict;
      }
    },
    // 所有用户
    async getAllUser() {
      const res = await getAllUser();
      console.log('所有用户', res);
      let userListDict = res.data.map(x => ({ value: x.userId + '', text: x.employeeName }));
      let targetTableItems = [findTableItem(this.columns, 'SERVICE_ADVISOR')];
      targetTableItems.forEach(item => {
        item.dictItems = userListDict;
      });
    }
  }
};
</script>
<style lang="less" scoped></style>
